/* 
 * Created on 9. September 2008, 01:08
 *
 *      Copyright 2008 Oliver Eichner <o.eichner@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
/**
 * @file DeviceTreeView.h
 * TreeView widget header for the devies
 */

#ifndef _DEVICETREEVIEW_H
#define	_DEVICETREEVIEW_H

#include <gtkmm.h>
#include <gtkmm/filefilter.h>
#include <gtkmm/menu_elems.h>
#include <gtkmm/menu.h>
#include <gtkmm/container.h>
#include <gtkmm/dialog.h>
#include <gdkmm-2.4/gdkmm.h>
#include <locale>
#include <sstream>
#include <list>
#include <fstream>
#include <string>
#include <iostream>

#include "DeviceDetailDialog.h"
#include "Device.h"
#include "CommentDialog.h"
#include "text.h"
#include "SaveToFileDialog.h"



using namespace std;

/**
 * @class CellItem_Device
 * The TreeView Device Items
 * @author Oliver Eichner
 * @version 0.0.93
 */
class CellItem_Device {
public:
    CellItem_Device();
    CellItem_Device(string tbridge, string devicename,
            string vendor, string model,
            string size, bool writeblocked, bool hpa_inUse,
            bool dco_inUse, bool security_inUse);
    CellItem_Device(const CellItem_Device& src);
    ~CellItem_Device();
    CellItem_Device & operator=(const CellItem_Device& src);

    Glib::ustring tp_tbridge;
    Glib::ustring tp_devicename;
    Glib::ustring tp_vendor;
    Glib::ustring tp_model;
    Glib::ustring tp_size;
    bool tp_writeblocked;
    bool tp_hpa_inUse;
    bool tp_dco_inUse;
    bool tp_security_inUse;

};

/**
 * @class DeviceTreeView
 * The class for displaying the Device TreeView
 * @author Oliver Eichner
 * @version 0.0.92
 */
class DeviceTreeView : public Gtk::TreeView {
public:
    DeviceTreeView();
    DeviceTreeView(const DeviceTreeView& orig);
    virtual ~DeviceTreeView();
    //    virtual void fillTree();
    virtual void reload();
    virtual void hideColumn(DevTreeEnum column);
    virtual bool somethingSelected();
    virtual Device& get_SelectedDeviceIterator();
    
    virtual void on_menu_file_popup_AddComment();
        virtual void on_menu_file_popup_Details();
    virtual void on_menu_file_popup_Save();
    // Override Signal handler:
    // Alternatively, use signal_button_press_event().connect_notify()
    virtual bool on_button_press_event(GdkEventButton *ev);
protected:
    virtual void create_model();
    virtual void add_columns();
    virtual void add_items();
    virtual void liststore_add_item(const CellItem_Device& tp_items);
    

    //Signal handler for popup menu items:
    virtual void on_menu_file_popup_generic();


    
    virtual void on_menu_file_popup_Print();

    virtual list<Device>::iterator findDeviceIter(Glib::ustring deviceName);

    virtual void dialogPrint(list<Device>::iterator nDeviceIter);
   
  

    Glib::RefPtr<Gtk::ListStore> tp_refListStore;
    typedef std::vector<CellItem_Device> type_vecItems;
    type_vecItems tp_vecItems;
    //Tree model columns:

    /**
     * @class DeviceTreeView::ModelColumns
     * The Columns for the treeview
     */
    class ModelColumns : public Gtk::TreeModel::ColumnRecord {
    public:

        ModelColumns() {
            add(tp_col_tbridge);
            add(tp_col_devname);
            add(tp_col_vendor);
            add(tp_col_model);
            add(tp_col_size);
            add(tp_col_writeblocked);
            add(tp_col_hpa_inUse);
            add(tp_col_dco_inUse);
            add(tp_col_security_inUse);
        }
        Gtk::TreeModelColumn<Glib::ustring> tp_col_tbridge;
        Gtk::TreeModelColumn<Glib::ustring> tp_col_devname;
        Gtk::TreeModelColumn<Glib::ustring> tp_col_vendor;
        Gtk::TreeModelColumn<Glib::ustring> tp_col_model;
        Gtk::TreeModelColumn<Glib::ustring> tp_col_size;
        Gtk::TreeModelColumn<bool> tp_col_writeblocked;
        Gtk::TreeModelColumn<bool> tp_col_hpa_inUse;
        Gtk::TreeModelColumn<bool> tp_col_dco_inUse;
        Gtk::TreeModelColumn<bool> tp_col_security_inUse;
    };

    ModelColumns tp_Columns;

    //The Tree model:
    Glib::RefPtr<Gtk::ListStore> tp_refTreeModel;

    Gtk::Menu tp_Menu_Popup;

    list<Device> DeviceList;

    enum ResponseType {
        response_Save,
        response_Print
    };
};



#endif	/* _DEVICETREEVIEW_H */

